package com.xuly.process.service;

import org.activiti.engine.RuntimeService;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
import org.activiti.engine.runtime.Execution;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("ReceiveTaskService")
public class ReceiveTaskService implements JavaDelegate {

    @Autowired
    private RuntimeService runtimeService;

    @Override
    public void execute(DelegateExecution delegateExecution) {
        System.out.println("进入---" + getClass().getSimpleName());

        int i=1/0;

        String pid = delegateExecution.getProcessInstanceId();

        System.out.println("runtimeService："+runtimeService);
        System.out.println("流程实例ID："+pid);
        Execution execution = runtimeService.createExecutionQuery()
                .processInstanceId(pid)
                .activityId("ReceiveTask")
                .singleResult();

        if (execution != null) {
            System.out.println("执行ID:" + execution.getId());
            System.out.println("执行名字:" + execution.getName());
            System.out.println("流程实例ID:" + execution.getProcessInstanceId());
            System.out.println("节点ID:" + execution.getActivityId());
            System.out.println("上个执行ID:" + execution.getParentId());
        } else {
            System.out.println("没有找到执行对象！");
        }
//        runtimeService.signalEventReceived(execution.getId());

        System.out.println("结束---" + getClass().getSimpleName());
    }
}
